package com.mjh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mjh.bean.Activity;
import com.mjh.bean.User;
import com.mjh.mapper.ActivityMapper;
import com.mjh.model.BaseQuery;
import com.mjh.query.ActivityQueryCondition;
import com.mjh.service.ActivityService;
import com.mjh.utils.AuthUtil;
import com.mjh.vo.ActivityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public PageInfo<ActivityVo> queryActivityListPage(ActivityQueryCondition activityQueryCondition) {
        PageHelper.startPage(activityQueryCondition.getCurrent(), activityQueryCondition.getSize());
        List<ActivityVo> pageInfo =  activityMapper.selectList(new BaseQuery(),activityQueryCondition);
        return new PageInfo<>(pageInfo);
    }

    @Override
    public Boolean saveActivity(Activity activity) {
        Integer userId = AuthUtil.getLoginUserId();
        activity.setOwnerId(userId);
        activity.setCreateBy(userId);
        activity.setCreateTime(new Date());
        return activityMapper.insertSelective(activity)>0;
    }

    @Override
    public ActivityVo queryActivityById(Integer id) {

        return activityMapper.selectByActivityId(id);
    }

    @Override
    public Boolean modifyActivity(Activity activity) {
        activity.setEditTime(new Date());
        activity.setEditBy(AuthUtil.getLoginUserId());
        return activityMapper.updateByPrimaryKeySelective(activity)>0;
    }

    @Override
    public Boolean removeActivity(Integer id) {
        return activityMapper.deleteByPrimaryKey(Long.valueOf(id))>0;
    }

    @Override
    public Boolean removeActivityBatch(List<Integer> ids) {
        return activityMapper.deleteActivityBatchByIds(ids)>0;
    }

    @Override
    public ActivityVo queryActivityDetailById(Integer id) {

        return activityMapper.selectActivityDetailInfoById(id);
    }

    @Override
    public List<Activity> queryActivityList() {

        return activityMapper.selectActivityList();
    }
}
